﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CoolCode.Entities;
using CoolCode.Services;
using CoolCode.Web;
using CoolCode.Linq;
using CoolCode.WebServices;

namespace CoolCode.Web.UI.Views.IC
{
    public partial class Cancel : SearchPage<Inspection, IInspectionService>
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            productList.EnableCheckBox = true;
            handleEvents();
            if (!IsPostBack)
            { 
            }
        }

        public override IQueryBuilder<Inspection> CreateFilter()
        {
            return productFilter.CreateFilter().Custom(c => c.Status == ProductStatus.Out.GetAttachedString());
        }

        protected void handleEvents()
        {
            this.Setup(lnkSearch, productList, c =>
            {
                var list = c.Result;
                productList.Model = c.Result;
                productList.DataBind();
                udpHeader.Update(); 
            },
            c =>
            {
                udpHeader.Alert(c.Exception);
            });

            //pgrMaster.PageIndexChanging += (sender, e) => this.ProvideData(new PageParam(e.NewPageIndex, this.PageSize));             

            this.Setup(exporter, new ExportService());

            lnkCancel.Click += new EventHandler(lnkCancel_Click);
        }

       protected   void lnkCancel_Click(object sender, EventArgs e)
        {
            List<string> selected = productList.GetSelections();
            if (selected.Count == 0)
            {
                udpHeader.Alert("请选中需要出库的产品，然后点【撤销】");
                return;
            }
            this.Service.Cancel(selected, UserName, DateTime.Now.Date, null);
        }
    }
}
